/**
 * @author 酱油鲜 (871839012@qq.com)
 * @since 2015-7-30 
 *    
 */

//常量,搜索类型种类
window.SEARCH_TYPE={
		"设备":"101",
		"DNS":"201",
		"域名":"202",
		"IPv4地址":"203",
		"MX记录":"204",
		"网络块":"205",
		"NS记录":"206",
		"URL":"207",
		"网站":"208",
		"地点":"301",
		"别号":"501",
		"文件":"502",
		"邮箱":"503",
		"图像":"504",
		"人":"505",
		"电话号码":"506",
		"词组":"507",
		"Facebook":"601",
		"QQ":"602",
		"微信":"603",
		"人人":"604",
		"Sina":"605",
		"豆瓣":"606",
		"知乎":"607"	
};

//右键菜单 
var right_theme=[];
require.config({
    paths: {
        echarts: '../dist/js'
    }
});
/*
 * 左侧导航菜单 menu.min.js 
 * 支持配置参数 a={
 * 		backicon：后退图标
 * 		animation:动画方式可选[fadeIn,botfadeInRight,botfadeInLeft,botflipInX,botflipInY,botfadeInUpBig,botfadeInDownBig,botfadeInLeftBig,botfadeInRightBig,botbounceIn,botbounceInUp,botbounceInDown,botbounceInLeft,botbounceInRight]
 * 		position:方向
 * 	}
 * 回调函数T(clickName) 
 * 最终完成时间：2015-7-31 19:52:12
 * @author 酱油鲜
 */
$.MetroMenu=function(a,T){var n=0,K=0,aa=1,F=0,J=-1,N=-1,R=0,O=0,E=false,H=false,P=0,ab=0;a=$.extend({animation:"fadeInLeft",position:"left",withtooltip:true,backicon:"static/img/back.png",closeonclick:true,escclose:true,color1:"#111111",color2:"#262626",items:[]},a);if(n==1){$(".MetroMenuBox").remove();$(".MetroToolTip").remove();$(window).unbind("resize")}n=1;K=a.items.length;aa=K-1;a.position=a.position.toLowerCase();if(a.position=="top"||a.position=="bottom"){var V='<div align="center" class="MetroMenuBox animated fadeIn fast" style="background-color: '+a.color1+';">';V+='<div align="center" class="MenuOptionBar animated fadeIn fast" id="MenuOptionBar">';V+="</div>";V+='<div align="center" class="SubMenuOptionBar animated fadeIn fast" id="SubMenuOptionBar">';V+="</div>";V+="</div>";$("body").append(V)}else{var V='<div class="MetroMenuBox animated fadeIn fast" style="background-color: '+a.color1+';">';V+='<div class="MenuOptionBar animated fadeIn fast" id="MenuOptionBar">';V+="</div>";V+='<div class="SubMenuOptionBar animated fadeIn fast" id="SubMenuOptionBar">';V+="</div>";V+="</div>";$("body").append(V);$(".MetroMenuBox").show();$(".MetroMenuBox").css("text-align","center");$(".MenuOptionBar,.SubMenuOptionBar").niceScroll({cursorcolor:"#00ccfF",cursorborder:"0",})}var Z='<div class="MetroToolTip" style="background-color: '+a.color1+';">';Z+='<div class="ToolImagen animated fast">';Z+='<img src="" id="ActiveIcon">';Z+='<img src="" id="ActiveIconSub1">';Z+="</div>";Z+='<div class="ToolText animated fast">';Z+='<span id="toolTitle">Programas</span>';Z+='<span id="toolText"></span>';Z+="</div>";Z+="</div>";$("body").append(Z);U();L();var Y="";for(var i=0;i<K;i++){var D=" ";var I=0;if(a.items[i].items!=undefined){if(a.items[i].items.length==1){D="1 option";I=1}else{D=a.items[i].items.length+" options";I=a.items[i].items.length}}if(a.items[i].link==undefined){Y+='<div class="MenuOption" id="MenuOption'+i+'" picture="'+a.items[i].icon+'" optionname="'+a.items[i].name+'" submenuitems="'+D+'" SubMenuOptionsNumber="'+I+'" menuoptionI="'+i+'">';Y+='<img src="'+a.items[i].icon+'" class="MenuIcon" OptionName="'+a.items[i].name+'">';Y+='<span class="MenuOptionText" >'+a.items[i].name+"</span>";Y+="</div>"}else{Y+='<a href ="'+a.items[i].link+'" style="border-style: none">';Y+='<div class="MenuOption" id="MenuOption'+i+'" picture="'+a.items[i].icon+'" optionname="'+a.items[i].name+'" submenuitems="'+D+'" SubMenuOptionsNumber="'+I+'" menuoptionI="'+i+'">';Y+='<img src="'+a.items[i].icon+'" class="MenuIcon" OptionName="'+a.items[i].name+'" style="border-style: none">';Y+='<span class="MenuOptionText" border="none">'+a.items[i].name+"</span>";Y+="</div>";Y+="</a>"}}$("#MenuOptionBar").append(Y);G();W();if(a.position=="left"||a.position=="right"){Q()}else{M()}$(".MenuOption").hover(function(){var c=$(this).attr("id");$("#"+c).css("background-color",a.color2)},function(){var c=$(this).attr("id");$("#"+c).css("background-color","transparent")});$(".MetroMenuBox").hover(function(){ab=1},function(){ab=0});$(".MenuOption").bind("mouseover",function(e){var f=$(window).width();if(f>=601){if(a.withtooltip===false){$(".MetroToolTip").hide()}else{$(".MetroToolTip").show()}}else{$(".MetroToolTip").hide();return 0}if(H==false){$(".MetroToolTip").show().addClass("animated fadeIn fast");H=true}$(".ToolImagen").removeClass("fadeIn").delay(200).queue(function(){$(this).addClass("fadeIn");$(this).dequeue()});var c=$(this).attr("picture");var e=$(this).attr("optionname");var d=$(this).attr("submenuitems");$("#ActiveIcon").attr("src",c);$("#toolTitle").text(e);$("#toolText").text(d)}).bind("click",function(b){var c=$(this).attr("id");var f=$(this).attr("picture");var d=$(this).attr("menuoptionI");var g=$(this).attr("SubMenuOptionsNumber");var e=$(this).attr("optionname");if(g==0){if(typeof T=="function"){if(T){T(e)}}if(a.closeonclick===true){n=0;$(".MetroToolTip").removeClass("fast").addClass("fadeOut");$(".MetroMenuBox").addClass("fadeOut fast").delay(300).queue(function(){$(this).remove();$(this).dequeue();$(".MetroToolTip").remove()})}}else{$("#MenuOptionBar").removeClass("fadeIn").addClass("fadeOut").delay(200).queue(function(){$(this).hide();var h='<div class="BackArrow SubMenuIcon animated '+a.animation+'" backto="raiz">';h+='<img src="'+a.backicon+'" class="SubtitleMenuIcon">';h+="</div>";for(var j=0;j<g;j++){if(a.items[d].items[j].link==undefined){h+='<div class="SubMenuTitle SubMenuIcon" id="Men'+j+'" subicon="'+a.items[d].items[j].icon+'" optionname="'+a.items[d].items[j].name+'">';h+='<img src="'+a.items[d].items[j].icon+'" class="SubtitleMenuIcon">';h+='<span class="MenuOptionText"  >'+a.items[d].items[j].name+"</span>";h+="</div>"}else{h+='<a href ="'+a.items[d].items[j].link+'" style="border-style: none">';h+='<div class="SubMenuTitle SubMenuIcon" id="Men'+j+'" subicon="'+a.items[d].items[j].icon+'" optionname="'+a.items[d].items[j].name+'">';h+='<img src="'+a.items[d].items[j].icon+'" class="SubtitleMenuIcon" border="none">';h+='<span class="MenuOptionText">'+a.items[d].items[j].name+"</span>";h+="</div>";h+="</a>"}}$(".SubMenuOptionBar").append(h);if(a.position=="top"||a.position=="bottom"){$(".SubMenuTitle").css("width","90px");$(".SubMenuTitle").css("float","left");$(".BackArrow").css("float","left");$(".BackArrow").css("width","90px");$(".SubMenuTitle").css("padding-top","10px");$(".SubMenuTitle").css("padding-bottom","5px");$(".SubtitleMenuIcon").css("height","50px");R=-1;X(g)}else{R=-1;X(g);P=g;S(g)}$(".SubMenuTitle").bind("mouseover",function(){var k=$(this).attr("subicon");$("#ActiveIconSub1").show().removeClass("animated fadeOut fast").addClass("animated fadeInLeft");$("#ActiveIconSub1").attr("src",k)});$(".SubMenuTitle").hover(function(){var k=$(this).attr("id");$("#"+k).css("background-color",a.color2)},function(){var k=$(this).attr("id");$("#"+k).css("background-color","transparent")});$(".SubMenuTitle").bind("click",function(){var k=$(this).attr("optionname");var l=a.items[d].name;if(typeof T=="function"){if(T){T(k)}}if(a.closeonclick===true){n=0;$(".MetroToolTip").removeClass("fast").addClass("fadeOut");$(".MetroMenuBox").addClass("fadeOut fast").delay(300).queue(function(){$(this).remove();$(".MetroToolTip").remove()})}});$(".BackArrow").bind("click",function(){var k=$(this).attr("backto");$(".SubMenuTitle").removeClass(a.animation).addClass("fadeOut");$("#ActiveIconSub1").show().removeClass("animated "+a.animation).addClass("animated fadeOut fast");$(this).removeClass(a.animation).addClass("fadeOut").delay(300).queue(function(){$(this).remove();$(".SubMenuTitle").remove();$("#MenuOptionBar").dequeue();$("#ActiveIconSub1").dequeue();$("#MenuOptionBar").removeClass("fadeOut").show()})})})}});$(window).bind("resize",function(){if(a.position=="top"||a.position=="bottom"){var c=navigator.userAgent.match(/iPad/i)!=null;if(c===false){G();W()}}else{Q();S(P)}});if(a.escclose===true){$(document).keyup(function(c){if(c.keyCode==27){n=0;$(".MetroToolTip").removeClass("fast").addClass("fadeOut");$(".MetroMenuBox").addClass("fadeOut fast").delay(200).queue(function(){$(this).remove();$(".MetroToolTip").remove()})}}).bind("mousedown",function(e){if(!($(e.target).closest(".MetroMenuBox").length>0)||$(e.target).closest(".right_main_menu").length>0){n=0;$(".MetroToolTip").removeClass("fast").addClass("fadeOut");$(".MetroMenuBox").addClass("fadeOut fast").delay(200).queue(function(){$(this).remove();$(".MetroToolTip").remove()});$(this).unbind("mousedown")}})}function M(){var d=$(window).height();var c=$(window).width()}function Q(){$(".MenuIcon").css("height","50px");$(".MenuOption").css("font-size","18px");var e=$(window).height();var l=$(window).width();var d=$("#MenuOptionBar").css("height");var j=K*100;e=e*1;d=d.replace("px","");if(l>=601){}else{$(".MetroToolTip").hide()}if(e<300){$(".MenuOptionText").hide();$(".MetroMenuBox").css("padding-left","10px");$(".MetroMenuBox").css("padding-right","10px");$(".MenuOption").css("padding-bottom","2px");$(".MenuOption").css("padding-top","2px");$(".MenuOption").css("padding-bottom","2px");$(".MetroMenuBox").css("width","25px")}else{$(".MenuOptionText").show();$(".MetroMenuBox").css("width","100px");$(".MetroMenuBox").css("padding-left","5px");$(".MetroMenuBox").css("padding-right","5px");$(".MenuOption").css("padding-top","10px");$(".MenuOption").css("padding-bottom","10px")}if(e<j){$(".MenuOption").css("padding-bottom","10px");var d=$("#MenuOptionBar").css("height");d=d.replace("px","");d=d-20;if(e<450){$(".MetroMenuBox").css("width","50px")}else{$(".MetroMenuBox").css("width","80px")}if(e<d){var k=d-e;var g=50;var h=g*K;h=h-k;var m=h/K;var f=m+20;m=m+"px";$(".MenuIcon").css("height",m);$(".MenuOption").css("font-size","15px");if(e>450){var c=$(".MenuOption").css("width");$(".MetroMenuBox").css("width","70px")}else{$(".MetroMenuBox").css("width",f+"px")}}}}function M(){}function S(f){f=parseInt(f)+1;$(".SubtitleMenuIcon").css("height","50px");$(".SubMenuOptionBar").css("font-size","18px");var g=$(window).height();var d=$(".SubMenuOptionBar").css("height");var h=f*100;d=d.replace("px","");if(g<300){$(".MenuOptionText").hide();$(".MetroMenuBox").css("padding-left","10px");$(".MetroMenuBox").css("padding-right","10px");$(".SubMenuTitle").css("padding-bottom","2px");$(".SubMenuTitle").css("padding-top","2px");$(".SubMenuTitle").css("padding-bottom","2px");$(".MetroMenuBox").css("width","25px")}else{$(".MenuOptionText").show();$(".MetroMenuBox").css("width","100px");$(".MetroMenuBox").css("padding-left","5px");$(".MetroMenuBox").css("padding-right","5px");$(".SubMenuTitle").css("padding-top","10px");$(".SubMenuTitle").css("padding-bottom","10px")}if(g<h){$(".SubMenuOptionBar").css("padding-bottom","10px");var d=$("#SubMenuOptionBar").css("height");d=d.replace("px","");d=d-20;if(g<d){var k=d-g;var e=50;var j=e*f;j=j-k;var c=(j/f);c=c+"px";$(".SubtitleMenuIcon").css("height",c);$(".SubMenuOptionBar").css("font-size","15px")}}}function W(){if(J==0){return 0}if(E===false){E=true;O=aa/2;O=Math.floor(O);if(aa%2==0){J=O;N=O;$("#MenuOption"+J).addClass("animated "+a.animation).css("opacity",1).delay(120).queue(function(c){J+=1;$(this).show();W()});$("#MenuOption"+N).addClass("animated "+a.animation).css("opacity",1);N-=1}else{J=O;N=O+1;$("#MenuOption"+J).addClass("animated "+a.animation).css("opacity",1).delay(150).queue(function(c){J+=1;W()});$("#MenuOption"+N).addClass("animated "+a.animation).css("opacity",1);N-=1}}$("#MenuOption"+J).addClass("animated "+a.animation).css("opacity",1).delay(150).queue(function(c){J+=1;W()});$("#MenuOption"+N).addClass("animated "+a.animation).css("opacity",1);N-=1}function X(c){if(R<c){if(R==-1){$("#Men0").delay(100).queue(function(){R=0;X(c)})}else{$("#Men"+R).show();$("#Men"+R).dequeue();$("#Men"+R).addClass("animated "+a.animation).delay(100).queue(function(){R+=1;X(c)})}}}function L(){switch(a.animation){case"fadeIn":a.animation+=" fast";break;case"fadeInRight":a.animation+=" fast";break;case"fadeInLeft":a.animation+=" fast";break;case"fadeInUp":a.animation+=" fast";break;case"fadeInDown":a.animation+=" fast";break}}function U(){switch(a.position){case"left":$(".MetroMenuBox").css("left","0px");$(".MetroMenuBox").css("height","100%");$(".MetroMenuBox").css("width","75px");$(".MetroMenuBox").css("top","0px");$(".MetroToolTip").css("bottom","10px");$(".MetroToolTip").css("right","10px");break;case"right":$(".MetroMenuBox").css("right","0px");$(".MetroMenuBox").css("height","100%");$(".MetroMenuBox").css("width","75px");$(".MetroMenuBox").css("top","0px");$(".MetroToolTip").css("bottom","10px");$(".MetroToolTip").css("left","10px");break;case"top":$(".MetroMenuBox").css("top","0px");$(".MetroMenuBox").css("left","0px");$(".MetroMenuBox").css("width","100%");$(".MetroToolTip").css("bottom","10px");$(".MetroToolTip").css("right","20px");break;case"bottom":$(".MetroMenuBox").css("bottom","0px");$(".MetroMenuBox").css("left","0px");$(".MetroMenuBox").css("width","100%");$(".MetroToolTip").css("top","10px");$(".MetroToolTip").css("right","20px");var c=navigator.userAgent.match(/iPad/i)!=null;if(c===true){$(".MetroMenuBox").css("padding-bottom","15px")}break;default:$(".MetroMenuBox").css("left","0px");$(".MetroMenuBox").css("height","100%");$(".MetroMenuBox").css("width","10px");$(".MetroToolTip").css("right","10px");break}}function G(){switch(a.position){case"left":break;case"right":break;case"top":$(".MenuOption").css("width","100px");$(".MenuOption").css("float","left");$(".MenuOption").css("padding-top","10px");$(".MenuOption").css("padding-bottom","5px");break;case"bottom":$(".MenuOption").css("width","100px");$(".MenuOption").css("float","left");$(".MenuOption").css("padding-top","10px");$(".MenuOption").css("padding-bottom","5px");break;default:break}}}
//主加载类
function Loadforce(dom){
	this.option={};//saveAsImage : {show: false}{dataView : {show: false, readOnly: false},// 根节点位置  {x: 100, y: 'center'}// vertical horizontal radial
	this.myChart=null;//echarts实例
	this.id=0;//用户增加节点的id
	this.category_id=0;//分组
	this.ecConfig=null;//常用配制
	
	
	var resize_dom=$(".toolbox-menu[role='edit_wh']");
	var _dom_h=resize_dom.find("[name='main_h']");
	var _dom_w=resize_dom.find("[name='main_w']");
	
	//初始化函数
	var _selt=this;
	var sou_name="";//选择连线 源
	var select_nonde={};
	_selt.dom=dom;
	_selt.option={backgroundColor:'rgb(19, 19, 19)',calculable:true,//toolbox: {show : true,feature : {restore : {show: true}}},
	    series : [{type:'force',name : "Force tree",//linkSymbol: 'arrow',
	                  	ribbonType: false,
	                  	categories : [{name: '1'}],
	                  	itemStyle: {normal: {color: '#4883b4',label: {show: true,position: 'bottom',formatter: "{b}",textStyle: {color: '#fff',fontSize: 12,baseline:'bottom'}},
		                    lineStyle: {color: '#ccc', type: 'dotted' }// 'curve'|'broken'|'solid'|'dotted'|'dashed'  
		                },emphasis: {color: '#4883b4',label: {show: false},borderWidth: 0}},
	                	roam:true,
	                  	scaling: 1,
	                  	nodes : [],
	                  	links : []
	              }
	          ]
	};
	_selt.getZr=function(){
		return _selt.myChart.getZrender();
	};
	_selt.setRoot=function(root){
		if(_selt.option.series[0].nodes.length==0){
			_selt.option.series[0].nodes.push(root);
			require(['echarts','echarts/chart/force','echarts/chart/tree'],
		            function (ec) {
						_selt.myChart = ec.init(_selt.dom); 
						_selt.myChart.setOption(_selt.option);
						_selt.ecConfig = require('echarts/config');
						
						_selt.myChart.on(_selt.ecConfig.EVENT.CONTEXTMENU,_selt._rightclick);
						_selt.myChart.on(_selt.ecConfig.EVENT.DBLCLICK,_selt._editName);
						//_selt.myChart.on(_selt.ecConfig.EVENT.CLICK,function(){alert(3333);});
						window.onresize = _selt.myChart.resize;
						//_selt.myChart.on("keypress",function(e){
						//	alert(1)
						//});
						//myChart.on(ecConfig.EVENT.DATA_ZOOM,loadforce.prototype.testZoom);
						//document.getElementById('main').onmousewheel = function (e){
							//alert(this.style.zoom);
						//}
		 	});
		}else{
			var repeatNode = _selt.option.series[0].nodes.filter(function (n){ var name =n.name;return name.replace(/\(\d+\)/,"") == root.name;});
			if(repeatNode.length != 0){
				_selt.option.series[0].categories.push({"name":++_selt.category_id});
				root.category=_selt.category_id;
				root.name=root.name+"("+repeatNode.length+")"
			}
			_selt.option.series[0].nodes.push(root);
			_selt.myChart.setOption(_selt.option);
		}
	};
	//绑定右键菜单事件
	_selt._rightclick=function(param){
		var e= param.event;
		var data = param.data;
		select_nonde=data;
		context.show(data,e);
	};
	//修改名称
	_selt._editName=function(p){
		var e=p.event;
		var d=p.data;
		var editNameDom=$(".toolbox-menu[role='edit_node_name']");
		editNameDom.css({top:e.clientY+10+"px",left:e.clientX-60+"px"}).fadeIn(500);
		editNameDom.find("input").on('keypress',function(event){
			event.preventDefault();
			if(event.keyCode==13){
				var n=$(this).val();
				if(n==""||n==null||n==d.name){
					$.jGrowl({header: "警告",message: '请输入一个有效的值'});
					return ;
				}
				var repeatNode = _selt.option.series[0].nodes.filter(function (t){return t.name == n;});
				//alert(repeatNode.length);
				if(repeatNode.length == 0){
					$.each(_selt.option.series[0].nodes,function(i,j){
						if(j.name==d.name){
							j.name=n;
							//j.initial[0]=e.pageX;
							//j.initial[1]=e.pageY;
							return true;
						}
					});
					$.each(_selt.option.series[0].links,function(i,j){
						if(j.source==d.name){
							j.source=n;
						}else if(j.target==d.name){
							j.target=n;
						}
					});
					_selt.myChart.setOption(_selt.option,false);
					editNameDom.hide();
					$(this).off("keypress").val("");
				}else{
					$.jGrowl({
                        header: "警告",
                        message: '值重复'
                    });
				}
			}
		});
		$('body').bind("mousedown",{id:".toolbox-menu"},onBodyDown);
	};
	//搜索全部
	_selt.event_alltransforms=function(e){
		//var pname=$(this).parents('body>.dropdown-context').data('target');
		var select = $(this).parents('body>.dropdown-context').data('target');
		jQuery.get("../hello",[{name:"name",value:select['name']}],function(jsonData){
			$.each(jsonData,function(i,j){
				//alert(j.target+":"+j.types+":"+t_obj.category);
				var t={
						name:j.target,
						types:j.types,
						//symbol:'image://周鸿祎.jpg',
						category:select.category,
                        symbolSize: [20, 20],
                        draggable: true,
                   // initial : [lf.id*30+10, 100],
                    //fixY : true,
                   // fixX : true
                   }
				var s={source : j.source, target : j.target, weight : 2,itemStyle: {normal: {width: 2,color: '#ff0000'}}}
				_selt.option.series[0].nodes.push(t);
				_selt.option.series[0].links.push(s);
				_selt.myChart.setOption(_selt.option);
				//_selt.addChildren(t,j);
			});
		},'json');
	};
	_selt.addChildren=function(dataNodes,dataLinks){
		_selt.option.series[0].nodes.push(dataNodes);
		_selt.option.series[0].links.push(dataLinks);
		_selt.myChart.setOption(_selt.option);
	};
	//修改类型事件
	_selt.event_edit_type=function(e){
		var __t=SEARCH_TYPE[e.data.name.replace(' ','')];
		$.each(_selt.option.series[0].nodes,function(i,j){
			if(j.name==select_nonde.name){
				j.types=__t;
				_selt.option.series[0].nodes.push(j);
				_selt.myChart.setOption(_selt.option);
				return true;
			}
		});
	};
	//取消操作
	_selt.event_cancel=function(e){
		_selt.myChart.un(_selt.ecConfig.EVENT.CLICK,_selt.addLink);//取消点击绑定选择事件
		sou_name="";//重置选择
	};
	//删除节点
	_selt.event_delNode=function(e){
		var select = $(this).parents('body>.dropdown-context').data('target');
		if(confirm("确认删除节点 ["+select.name+"]")){
			var l=_selt.option.series[0].nodes.length;
			for(var i=0;i<l;i++){
				if(_selt.option.series[0].nodes[i].name==select.name){
					_selt.option.series[0].nodes.remove(i);
					break;
				}
			}
			l=_selt.option.series[0].links.length;
			var it=[];
			for(var i=0;i<l;i++){
				if(_selt.option.series[0].links[i].source==select.name||_selt.option.series[0].links[i].target==select.name){
					it.push(i);
				}
			}
			for(var i=0,l=it.length;i<l;i++) _selt.option.series[0].links.remove(it[i]);
			_selt.myChart.setOption(_selt.option,true);
		}
	};
	//连线
	_selt.event_connection=function(e){
		sou_name=$(this).parents('body>.dropdown-context').data('target').name;
		_selt.myChart.on(_selt.ecConfig.EVENT.CLICK,_selt.addLink);
	}
	_selt.addLink=function(p){
		if(p.data.name!=sou_name){
			var l={source : sou_name, target : p.data.name, weight : 5,itemStyle: {normal: {width: 2}}};
			_selt.option.series[0].links.push(l);
			_selt.myChart.setOption(_selt.option);
			_selt.myChart.un(_selt.ecConfig.EVENT.CLICK);
		}else
			$.jGrowl({
                header: "警告",
                message: '不能选择自己'
            });
	}
	context.init(_selt);//初始化菜单
	
	_selt.resize_full=function(e){
		resize_dom.fadeIn(500);
		$('body').bind("mousedown",{id:".toolbox-menu"},onBodyDown);
	}
	
	_selt.onsize=function(e){
		_dom_h.val(_selt.dom.offsetHeight);
		_dom_w.val(_selt.dom.offsetWidth);
	}
	
	_dom_h.bind("keyup",function(e){
		_selt.dom.style.height=$(this).val()+"px";
		_selt.myChart.resize();
	});
	_dom_w.bind("keyup",function(e){
		_selt.dom.style.width=$(this).val()+"px";
		_selt.myChart.resize();
	});
	window.onresize=_selt.onsize;
	_selt.onsize();
	return _selt;
}
Array.prototype.remove=function(dx) {
    if(isNaN(dx)||dx>this.length){return false;} 
    for(var i=0,n=0;i<this.length;i++){ 
        if(this[i]!=this[dx]){ 
            this[n++]=this[i] 
        } 
    } 
    this.length-=1;
    return this;
}
function delloadAnimation(){
	var parentD = $("#universal-preloader");
	var pre = $("#universal-preloader>div");
	pre.delay(500).animate({opacity : '0'}, {duration : 400,complete : function() {
			parentD.animate({opacity : '0'}, {duration : 400,complete : function() {
					parentD.remove();
				}
			});
		}
	});
}
$(document).ready(function(){
	//alert(checkBrowser().nbw);
	delloadAnimation();//清除开始动画
	var lf=new Loadforce(document.getElementById('main'));
	$(".main_content").niceScroll({cursorcolor:"#00ccfF",cursorborder:"0",});//设置左侧导航的滚动条
	$("#menu_show_btn").click(function(e) {
		$.MetroMenu({
            backicon: "../sortout/images/back.png",
            animation: "fadeInLeft",
            position: "left",
            withtooltip: true,
            closeonclick: true,
            escclose: true,
            "items": [{"name":"设备","icon":"../sortout/images/calendar.png"},{"name":"基础设施","icon":"../sortout/images/office.png","items":[{"name":"DNS","icon":"../sortout/images/word.png"},{"name":"域名","icon":"../sortout/images/excel.png"},{"name":"IPv4地址","icon":"../sortout/images/powerpoint.png"},{"name":"MX记录","icon":"../sortout/images/outlook.png"},{"name":"网络块","icon":"../sortout/images/outlook.png"},{"name":"NS记录","icon":"../sortout/images/outlook.png"},{"name":"URL","icon":"../sortout/images/outlook.png"},{"name":"网站","icon":"../sortout/images/outlook.png"}]},{"name":"地点","icon":"../sortout/images/outlook.png"},{"name":"Builwith技术","icon":"../sortout/images/outlook.png"},{"name":"个人","icon":"../sortout/images/mail.png","items":[{"name":"别号","icon":"../sortout/images/sent.png"},{"name":"文件","icon":"../sortout/images/mailopen.png"},{"name":"邮箱","icon":"../sortout/images/gmail.png"},{"name":"图像","icon":"../sortout/images/gmail.png"},{"name":"人","icon":"../sortout/images/gmail.png"},{"name":"电话号码","icon":"../sortout/images/gmail.png"},{"name":"词组","icon":"../sortout/images/gmail.png"}]},{"name":"社交网络","icon":"../sortout/images/ps.png","items":[{"name":"Facebook","icon":"../sortout/images/photoshop.png"},{"name":"QQ","icon":"../sortout/images/dw.png"},{"name":"微信","icon":"../sortout/images/dw.png"},{"name":"人人","icon":"../sortout/images/dw.png"},{"name":"Sina","icon":"../sortout/images/dw.png"},{"name":"豆瓣","icon":"../sortout/images/dw.png"},{"name":"知乎","icon":"../sortout/images/dw.png"}]}]
        },function(clickName){
        	//alert("选择了"+clickName+"");
        	console.log("选择了 ["+clickName+"] 类型  ["+SEARCH_TYPE[clickName.replace(' ','')]+"]");
        	var main=$(lf.dom);
			var types=SEARCH_TYPE[clickName.replace(' ','')];
			var str='<div class="search_type"><div><img src="../dist/img/siteicon/youku.jpg" alt=".."/></div>'
					+'<input type="text" name="d" value="周杰伦" /><input type="hidden" name="type" value="'+types+'"/></div>';
			var search_Obj=$(str).appendTo(main).css({top:'45%',left:'45%'});
			$("input[type='text']",search_Obj).on('keypress',function(e){
				if(e.keyCode==13){//设定根节点  位置待修改
						lf.setRoot({name:$(this).val(),
									types:types,
									//symbol:'image://周杰伦.jpg',
									category:0,
		                            symbolSize: [20, 20],
		                            draggable: true,
		                            id : lf.id++,
		                            //initial : [lf.id*30+10, 100],
		                            //fixY : true,
		                           // fixX : true
		                           });
						search_Obj.remove();
				}else if(e.keyCode==27){
					search_Obj.remove();
				}
			}); 
        });
	});
	$(".main_toolbox i.icon-resize-full").click(lf.resize_full);
	//截图
	$(".main_toolbox i.icon-picture").on("click", function(event) {  
        event.preventDefault();
        /*html2canvas(lf.dom, {  //.parentNode
        allowTaint: true,  
        taintTest: false,  
        onrendered: function(canvas) {  
            canvas.id = "mycanvas";          
            var dataUrl = canvas.toDataURL();
            var w=lf.dom.offsetWidth;
            var h=lf.dom.offsetHeight;
            var b_w=w-document.body.offsetWidth*0.95;
            var b_h=h-document.body.offsetHeight*0.95;
            if(b_w>0||b_h>0){//宽度或者高度超出
            	if(b_w>b_h){//宽度超出更多
            		w=document.body.offsetWidth*0.95;
            		h=h*(1-b_w/w);
            	}else{//高度超出更多
            		h=document.body.offsetHeight*0.95;
            		w=w*(1-b_h/h);
            	}
            }  
            	
            $("#sevaImg").empty().append($("<img src='"+dataUrl+"' title='右键->另存为'/>")).fadeIn(500);
            $("#sevaImg").find("img").css({height:h+"px",width:w+"px"});
            $("body").bind('keydown', 'esc',function (e){$("#sevaImg").hide();});
        }  
    	});*/ 
    	//alert(lf.getZr().getHight());
        var w=lf.dom.offsetWidth;
        var h=lf.dom.offsetHeight;
        var b_w=w-document.body.offsetWidth*0.95;
        var b_h=h-document.body.offsetHeight*0.95;
        if(b_w>0||b_h>0){//宽度或者高度超出
        	if(b_w>b_h){//宽度超出更多
        		w=document.body.offsetWidth*0.95;
        		h=h*(1-b_w/w);
        	}else{//高度超出更多
        		h=document.body.offsetHeight*0.95;
        		w=w*(1-b_h/h);
        	}
        }  
    	$("#sevaImg").empty().append($("<img src='"+lf.myChart.getDataURL('png')+"' title='右键->另存为'/>")).fadeIn(500);
    	 $("#sevaImg").find("img").css({height:h+"px",width:w+"px"});
        $("body").bind('keydown', 'esc',function (e){$("#sevaImg").hide();});
	});
});